//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    //点击导航菜单索引
    currentIndexNav: 0,
    // 首页导航数据
    navList: [],
    // 轮播图数据
    swiperList:[],
    // 视频列表数据
    videosList:[]

  },
  //点击首页导航按钮
  activeNav(e) {
    this.setData({
      currentIndexNav: e.target.dataset.index
    })
  },

  // 获取首页导航数据
  getNavList() {
    let that = this;
    wx.request({
      // url: 'https://easy-mock.com/mock/5c1dfd98e8bfa547414a5278/bili/navList',
      url: "https://www.fastmock.site/mock/0cc8353a68511aad722aa387610a4ce1/bili/navList",
      success(res) {
        if (res.data.code === 0) {
          that.setData({
            navList: res.data.data.navList
          })
        }
      }
    })
  },
  //获取轮播图数据
  getSwiperList(){
    let that = this;
    wx.request({
      // url: 'https://easy-mock.com/mock/5c1dfd98e8bfa547414a5278/bili/swiperList',
      url: 'https://www.fastmock.site/mock/0cc8353a68511aad722aa387610a4ce1/bili/swiperList',
      success(res) {
        console.log(res)
        if (res.data.code === 0) {
          that.setData({
            swiperList: res.data.data.swiperList
          })
        }
      }
    })
  },
  // 获取视频列表数据
  getVideosList(){
    let that = this;
    wx.request({
      // url: 'https://easy-mock.com/mock/5c1dfd98e8bfa547414a5278/bili/videosList',
      url: 'https://www.fastmock.site/mock/0cc8353a68511aad722aa387610a4ce1/bili/videosList',
      success(res) {
        console.log(res)
        if (res.data.code === 0) {
          that.setData({
            videosList: res.data.data.videosList
          })
        }
      }
    })
  },
  // 监听页面加载
  onLoad: function () {
    // 1 获取首页导航数据
    this.getNavList();
    // 2 获取轮播数据
    this.getSwiperList();
    // 3 获取视频列表数据
    this.getVideosList()
  },
  // 监听页面初次渲染完成
  onReady: function () {

  },
  // 监听页面显示
  onShow: function () {

  }

})